﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using Common.Utilities.Dispatcher;
using Workflows.Components.TextMining.Properties;

namespace Workflows.Components.TextMining.FullTextSearch
{
    /// <summary>
    /// 
    /// </summary>
    [Serializable]
    public class LuceneSearchComponent:WorkflowComponentBase
    {
        #region ctor
		/// <summary>
		/// 
		/// </summary>
        public LuceneSearchComponent()
			: base()
		{
			this.ComponentActivityType = WorkflowActivityType.SimpleActivity;
			this.ComponentCategory = WorkflowComponentCategory.TextMining.ToString();
			this.ComponentName = "Lucene Searcher";
			this.Description = "Search full text using lucene";
            this.ComponentIcon = Resources.apds_206;
            this.ComponentImage = Resources.vdt80pui_1053;

			this._Instruction =
				new LuceneSearchInstruction(this.ComponentID,Guid.Empty,
                    string.Empty, string.Empty, string.Empty,string.Empty,string.Empty,
                    new Dictionary<string, double>());
			this._Output=new LuceneSearchOutput(this.ComponentID,Guid.Empty,string.Empty);
		}
		#endregion

        #region Overrides of WorkflowComponentBase

        private LuceneSearchInstruction _Instruction;
        /// <summary>an object that encapsulate instruction settings.</summary>
        public override InstructionBase Instruction
        {
            get
            {
                return _Instruction;
            }
            set
            {
                _Instruction = (LuceneSearchInstruction) value;
            }
        }

        private LuceneSearchOutput _Output;
        /// <summary>an object to encapsulate output</summary>
        public override ResultBase Output
        {
            get
            {
                return _Output;
            }
            set
            {
                _Output = (LuceneSearchOutput) value;
            }
        }

        #endregion

        public override XmlNode Serialize(ref XmlDocument xDoc, ref XmlNode parentNode)
        {
            XmlNode xNode = base.Serialize(ref xDoc, ref parentNode);
            this.Instruction.Serialize(ref xDoc, ref xNode);
            return xNode;
        }

        public override WorkflowComponentBase Instantiate(XmlNode xNode)
        {
            LuceneSearchComponent component = (LuceneSearchComponent)base.Instantiate(xNode);
            component.Instruction = component.Instruction.Instantiate(xNode.SelectSingleNode("Instruction"));
            return component;
        }
    }
}
